package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.SmsControllerApi;
import com.nineclock.system.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sms")
public class SmsController implements SmsControllerApi {
    @Autowired
    SmsService smsService;

    /**
     * 短信验证码登录
     * @param mobile 手机号
     * @param type 类型 ???
     * @return
     */
    @GetMapping("/code")
    @Override
    public Result createSmsCode(@RequestParam("mobile") String mobile,@RequestParam("type") String type) {
        smsService.createSmsCode(mobile,type);
        return Result.success();
    }


    /**
     * 短信验证码效验
     * @param mobile
     * @param checkcode
     * @param type
     * @return
     */
    //verify?mobile=17792648116&checkcode=094813&type=3
    @GetMapping("/verify")
    public Result<Boolean> verifySms(@RequestParam("mobile") String mobile, @RequestParam("checkcode") String checkcode,@RequestParam("type") String type){
        Boolean flag= smsService.verifySms(mobile,checkcode,type);
        return Result.success(flag);
    }

}
